﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;

namespace Marbles.Core.Content.Themes
{
    public class ThemeCollection : ICollection<Theme>
    {
        public Theme this[int index] { get { return items[index]; } set { items[index] = value; } }

        public int Count
        {
            get { return items.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        private List<Theme> items = null;

        public ThemeCollection()
        {
            items = new List<Theme>();
            string path = HttpContext.Current.Server.MapPath("/App_Themes/");
            foreach (string directory in System.IO.Directory.GetDirectories(path))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(directory);
                //if (dirInfo.Name.ToLower() == "admin") { continue; }
                Theme t = new Theme(dirInfo.Name);
                items.Add(t);
            }
        }

        public void Add(Theme item)
        {
            items.Add(item);
        }

        public void Clear()
        {
            items.Clear();
        }

        public bool Contains(Theme item)
        {
            return items.Contains(item);
        }

        public void CopyTo(Theme[] array, int arrayIndex)
        {
            items.CopyTo(array, arrayIndex);
        }

        public bool Remove(Theme item)
        {
            return items.Remove(item);
        }

        public IEnumerator<Theme> GetEnumerator()
        {
            return items.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return items.GetEnumerator();
        }
    }
}